package org.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zhxy.model.entity.Teacher;
import org.zhxy.model.result.Result;
import org.zhxy.service.TeacherService;

import java.util.List;

@Slf4j
@Tag(name = "教师管理")
@RestController
@RequestMapping("/sms/teacherController")
@RequiredArgsConstructor
public class TeacherController {
    private final TeacherService teacherService;

    @Operation(summary = "分页条件查询教师列表")
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result getTeachers(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize, Teacher teacher) {
        log.info("分页条件查询教师列表，请求参数：{},{},{}", pageNo, pageSize, teacher);

        IPage<Teacher> page = new Page<>(pageNo, pageSize);
        teacherService.page(page, teacher);
        log.info("分页条件查询教师列表，响应数据：{}", page);

        return Result.ok(page);
    }

    @Operation(summary = "添加或修改教师信息")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@RequestBody Teacher teacher) {
        log.info("添加或修改教师信息，请求参数：{}", teacher);

        teacherService.saveOrUpdate(teacher);

        return Result.ok();
    }

    @Operation(summary = "批量删除教师信息")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(@RequestBody List<Integer> ids) {
        log.info("批量删除教师信息，请求参数：{}", ids);

        teacherService.removeByIds(ids);

        return Result.ok();
    }
}
